package 格子游戏;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    static int N = 40010, n, m;
    static int[] p = new int[N];

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String[] num = in.readLine().split(" ");
        n = Integer.parseInt(num[0]);
        m = Integer.parseInt(num[1]);
        for (int i = 0; i < n * n; i++) {
            p[i] = i;
        }
        int res = -1;
        for (int i = 0; i < m; i++) {
            String[] s = in.readLine().split(" ");
            int x = Integer.parseInt(s[0]);
            int y = Integer.parseInt(s[1]);
            x--;
            y--;
            int a = get(x, y), b = 0;
            if (s[2].equals("D")) {
                b = get(x + 1, y);
            } else {
                b = get(x, y + 1);
            }
            int pa = find(a);
            int pb = find(b);
            if (pa == pb) {
                res = i + 1;
                break;
            } else {
                p[pa] = pb;
            }
        }
        if (res == -1) {
            System.out.println("draw");
        } else {
            System.out.println(res);
        }
    }

    private static int find(int x) {
        if (x != p[x]) {
            p[x] = find(p[x]);
        }
        return p[x];
    }

    private static int get(int x, int y) {
        return x * n + y;
    }
}